#include <vector>
#include <iostream>
#include <list>
using namespace std;

int _index(std::vector<int> v, int x)
{
    auto begin = v.begin();
    auto end = v.end();
    return std::distance(begin, std::find(begin, end, x));
}

bool _l_v_equal(list<int> l1, std::vector<int> v2)
{
    if (l1.size() != v2.size())
        return false;
    auto lbegin = l1.cbegin();
    auto lend = l1.cend();
    auto vbegin = v2.cbegin();
    for (; lbegin != lend; ++lbegin, ++vbegin)
    {
        if (*lbegin != *vbegin)
            return false;
    }
    return true;
}

void _out_of_bound()
{
    vector<int> v;
    cout << v[0] << endl;       // segment fault
    cout << v.at(0) << endl;    // libc++abi: terminating due to uncaught exception of type std::out_of_range: vector
    cout << v.front() << endl;  // segment fault
    cout << *v.begin() << endl; // segment fault
}

void _vec_increase()
{
    /*
    size: 0 capacity:0
    size: 1 capacity:1
    size: 2 capacity:2
    size: 3 capacity:4
    size: 5 capacity:8
    size: 9 capacity:16
    size: 17 capacity:32
    */
    vector<int> v;
    int sz, cp;
    cout << "size: " << v.size() << " capacity:" << v.capacity() << endl;
    for (sz = v.size(), cp = v.capacity(); sz <= cp; sz++)
    {
        v.push_back(1);
    }
    cout << "size: " << v.size() << " capacity:" << v.capacity() << endl;

    for (sz = v.size(), cp = v.capacity(); sz <= cp; sz++)
    {
        v.push_back(1);
    }
    cout << "size: " << v.size() << " capacity:" << v.capacity() << endl;

    for (sz = v.size(), cp = v.capacity(); sz <= cp; sz++)
    {
        v.push_back(1);
    }
    cout << "size: " << v.size() << " capacity:" << v.capacity() << endl;

    for (sz = v.size(), cp = v.capacity(); sz <= cp; sz++)
    {
        v.push_back(1);
    }
    cout << "size: " << v.size() << " capacity:" << v.capacity() << endl;

    for (sz = v.size(), cp = v.capacity(); sz <= cp; sz++)
    {
        v.push_back(1);
    }
    cout << "size: " << v.size() << " capacity:" << v.capacity() << endl;

    for (sz = v.size(), cp = v.capacity(); sz <= cp; sz++)
    {
        v.push_back(1);
    }
    cout << "size: " << v.size() << " capacity:" << v.capacity() << endl;
}

int main()
{
    int a[] = {1, 2, 3, 4, 5};
    std::vector<int> v(a, a + 5);
    int i1 = _index(v, 3);
    cout << i1 << endl;

    // _out_of_bound();
    _vec_increase();
}